﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DSPL.Contracts;
using DSPL.Contracts.Common;
using DSPL.Contracts.Interfaces;
using DSPL.DataAccess;

namespace DSPL.Services.Services
{
    public class TransactionWriteService : ITransactionWriteService
    {
        DatabaseAccess db = DatabaseAccess.Instance ;
        public int PrimaryKey { get; set; }

        public string ReferenceNo { get; set; }

        #region IMasterWriteService Members

        

        #endregion

        #region private Methods

        private int GetPrimaryKey(string tableName, ref  SqlTransaction sqlTran)
        {
            List<ParameterWithValue> paramList = new List<ParameterWithValue>();
            paramList.Add(new ParameterWithValue("@tableName", tableName));
            paramList.Add(new ParameterWithValue("@nextPk", 0, SqlDbType.Int, ParameterDirection.InputOutput));

            SpCaller spCaller = new SpCaller() { SpName = "SP_GET_PRIMARYKEY", SpParamValues = paramList.ToArray() };
            return (int)db.Excecute(spCaller, "@nextPk", ref sqlTran);
        }

        private object GetDefaultVlue(string DataType)
        {
            object returnValue = null;

            switch (DataType)
            {
                case "STRING":
                    returnValue = string.Empty;
                    break;

                case "DATETIME":
                    returnValue = new DateTime(1900, 01, 01); ;
                    break;

                case "BOOLEAN":
                    returnValue = false;
                    break;

                case "INT16":
                    returnValue = 0;
                    break;

                case "UINT16":
                    returnValue = 0;
                    break;

                case "INT32":
                    returnValue = 0;
                    break;

                case "UINT32":
                    returnValue = 0;
                    break;

                case "INT64":
                    returnValue = 0L;
                    break;

                case "UINT64":
                    returnValue = 0;
                    break;

                case "LONG":
                    returnValue = 0L;
                    break;

                case "DECIMAL":
                    returnValue = 0.0M;
                    break;

                case "DOUBLE":
                    returnValue = 0.0D;
                    break;

                case "BYTE":
                    returnValue = 0;
                    break;

                case "SBYTE":
                    returnValue = 0;
                    break;

                 case "CHAR":
                    returnValue = "\0";
                    break;

                 case "SINGLE":
                    returnValue = 0.0F;
                    break;

                default:
                    break;
            }

            return returnValue;
        }

        #endregion


    }
}
